package com.study.samsung.Dao;

import com.study.samsung.Entity.*;
import com.study.samsung.Utils.RowMapper;
import com.study.samsung.Utils.SQLHelper;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class OrderXqDao {
    SQLHelper helper = new SQLHelper();

    public List<OrderDetails> selectAll(){
        String sql = "select * from order_details";
        return helper.query(sql,new OrderDetailsRowMapper());
    }

    public Integer ordersxqdel(Integer did){
        String sql = "delete from order_details where did = ?";
        return helper.update(sql,did);
    }

    public Integer ordersxqinsert(BigDecimal dxprice,int gnumber,int sxid,int did){
        String sql = "insert into order_details values(?,?,?,?,?)";
        return helper.update(sql,null,dxprice,gnumber,sxid,did);
    }

    public Integer ordersxqinserts(OrderDetails orderDetails){
        String sql = "insert into order_details values(?,?,?,?,?)";
        return helper.update(sql,null,orderDetails.getDxprice(),
                orderDetails.getGnumber(),
                orderDetails.getSxid(),
                orderDetails.getDid());
    }


    class OrderDetailsRowMapper implements RowMapper<OrderDetails>{

        @Override
        public OrderDetails map(ResultSet rs) throws SQLException {
            return new OrderDetails(rs.getInt("dxid"),
                    rs.getBigDecimal("dxprice"),
                    rs.getInt("gnumber"),
                    rs.getInt("sxid"),
                    rs.getInt("did"));
        }
    }
}
